import axios,{CancelToken} from "./config";

//封装登录接口请求
export const login = (username, password) =>
  axios({
    url: "/users/login",
    method: "post",
    data: {
      username,
      password
    }
  });

  
  
//获取登录日志
/**
 * 
 * @param {object} _this 一个组件实例 
 */
export const getLoginLog = (_this) => axios.get("/getloginlog",{
  cancelToken: new CancelToken(function(c){
    //C就是一个方法可以终端请求
    _this.cancel = c //相当于给组件实例添加一个cancelToken属性
  })
});

//获取用户菜单
export const getMenuList = () => axios.get("permission/getMenuList");

//获取学生数据
export const getStuList = (params={}) => axios({
  url: "/students/getstulist",
  method: "get",
  params
});

//上传学生信息
/**
 * 
 * @param {object} stuDetail dialog收集的学生信息 
 */
export const addStuDetail = (stuDetail) =>
axios({
  url: "/students/addstu",
  method: "post",
  data: stuDetail
});

//删除学生信息
export const delStu = (sId) => axios.get(`/students/delstu?sId=${sId}`)

//编辑学生信息
export const updateStu = (updated = {}) =>axios({
  url: "/students/updatestu",
  method: "post",
  data: updated
});
//搜索学生
export const searchStu = (params) => {
  return axios(
    {
      url:"/students/searchstu",
      params
    }
  )
}
//获取班级列表
export const getClasses = () => axios.get("/students/getclasses")

//获取验证码
export const setCaptcha = ()=>axios.get("/users/getCaptcha")

